package Thread;

import java.util.concurrent.CountDownLatch;

public class Demo44 {

    public static void main(String[] args) throws InterruptedException {

        //创建线程
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0 ; i < 10 ; i++){
            int id = i;
            Thread t = new Thread(() -> {
                System.out.println("线程启动: "+ id);
                try {
                    //假设这里进行一些 "下载" 这样的耗时操作
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程结束 : "+ id);
                latch.countDown(); //调用线程
            });
            t.start();
        }
        //通过 await 等待所有线程调用 countDown
        latch.await();
        System.out.println("所有线程结束");

    }
}
